<?php
class Controller_Admin_Guider extends Controller_Form
{
    public function __construct ($req, $res)
    {
        $this->_form_type = '';
        parent::__construct($req, $res);

        $this->_list_where = array(
//            array('status', '=', 'VALID'),
        );
    }


    public function action_index ($page = 1)
    {
        $this->action_list($page);
    }

    public function action_list($page = 1){
        $filter = $this->request->query();
        $userName = Arr::get($filter,'name');
        $type = Arr::get($filter,'type');
        $email = Arr::get($filter,'email');
        $mobile = Arr::get($filter,'mobile');
        $page     = max(1, $page);
        $limit    = 10;
        $offset   = $limit * ($page - 1);

        list($counts,$data) = User_Account::guider_account($userName,$type,$limit,$offset,$email,$mobile);

        $pagination = $this->pagination($counts, $limit);
        $this->template->set('pagination', $pagination);
        $this->template->set('data', $data);
        $this->template->set('filter', $filter);
//        var_dump($data);
        $this->template->set_filename('smarty:/admin/user/list');
    }

    public function action_credit($id){
        $post = $this->request->post();
        if(empty($post)){
            $data = User_Account::account_checkout('uid',$id)->current();
            if($data['identityName'] == '留学生'){
                $identity = explode('-|-',$data['identityErea']);
                $data['identityErea'] = Arr::get($identity,0).'-'.Arr::get($identity,1);
            }
            $data['identityPicture'] = explode(';',$data['identityPicture']);
            $this->template->set('data', $data);
            $this->template->set_filename('smarty:/admin/user/credit');
        }else{
            $allow = Arr::get($post,'allow');
            $uid = Arr::get($post,'uid');
            $deny = Arr::get($post,'deny');
            if($allow){
                $data = array('identityActive'=>1);
                Util_Notice::addNotice(-10,$uid,'您已完成身份认证，可至个人中心认证中查看。');
            }else{
                $data = array('identityActive'=>2);
                Util_Notice::addNotice(-10,$uid,'您的身份认证请求，因为上传材料或是填写信息不符合相关要求而未能通过认证。');
            }
            User_Account::update($data,'uid',$uid);

            $this->request->redirect('/admin/guider');
        }

    }


}


